<template>
	<view class="wrap">
		<swiper v-if="banner.length" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="#eee" indicator-active-color='#fa5320'>
			<swiper-item v-for="(item,index) in banner" :key="index">
				<view class="swiper-item">
					<image :src="item.Banner" mode="aspectFill"></image>
				</view>
			</swiper-item>
			
		</swiper>
		
		<!-- <view class="payBody">
			<view class="payBody_cell">
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
				<view class="payBody_tit">
					推荐1个
				</view>
				<view class="payBody_round" :class="level<1?'payBody_Opacity':''">
					<image v-if="level>0" src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/1742873293862622.png" mode="heightFix"></image>
				</view>
				<view class="payBody_tit payBody_old">
					立返	50
				</view>
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
			</view>
			<view class="payBody_line" :class="level<2?'payBody_Opacity':''"></view>
			
			<view class="payBody_cell">
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
				<view class="payBody_tit">
					推荐2个
				</view>
				<view class="payBody_round" :class="level<2?'payBody_Opacity':''">
					<image v-if="level>1" src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/1742873293862622.png" mode="heightFix"></image>
				</view>
				<view class="payBody_tit payBody_old">
					立返50
				</view>
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
			</view>
			<view class="payBody_line" :class="level<3?'payBody_Opacity':''"></view>
			
			<view class="payBody_cell">
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
				<view class="payBody_tit">
					推荐3个
				</view>
				<view class="payBody_round" :class="level<3?'payBody_Opacity':''">
					<image v-if="level>2" src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/1742873293862622.png" mode="heightFix"></image>
				</view>
				<view class="payBody_tit payBody_old">
					立返200
				</view>
				<view class="payBody_tit payBody_lit">
					再送¥100现金券
				</view>
			</view>
			<view class="payBody_line" :class="level<4?'payBody_Opacity':''"></view>
			
			
			<view class="payBody_cell">
				<view style="opacity: 0;" class="payBody_tit payBody_lit">
					再送¥150现金券
				</view>
				<view class="payBody_tit">
					推荐>3个
				</view>
				<view class="payBody_round" :class="level<4?'payBody_Opacity':''">
					<image v-if="level>3" src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/1742873293862622.png" mode="heightFix"></image>
				</view>
				<view class="payBody_tit payBody_old">
					立返10%
				</view>
				<view class="payBody_tit payBody_lit" style="opacity: 0;">
					再送¥150现金券
				</view>
			</view>
		</view> -->	
		
		
		<view class="payBody">
			<block v-for="(item,index) in vipPerson" :key="index">
				<view class="payBody_cell">
					<view style="opacity: 0;" class="payBody_tit payBody_lit">
						再送¥150现金券
					</view>
					<view class="payBody_tit">
						{{item.title}}
					</view>
					<view class="payBody_round" :class="level<item.count?'payBody_Opacity':''">
						<image v-if="level>(item.count-1)" src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/1742873293862622.png" mode="heightFix"></image>
					</view>
					<view class="payBody_tit payBody_old">
						{{item.money}}
					</view>
					<view class="payBody_tit payBody_lit" v-if="item.subtitle">
						{{item.subtitle}}
					</view>
					<view style="opacity: 0;" class="payBody_tit payBody_lit" v-else>
						再送¥150现金券
					</view>
				</view>
				<view class="payBody_line" v-if="index!=vipPerson.length-1" :class="level<(item.count+1)?'payBody_Opacity':''"></view>
			</block>
			
		</view>

		
		<view class="payBtn_body"  v-if="(user && user.UserType) && isVipFun(user.UserType)">
			<view class="payBtn_tag" @click="nav_to('/pages/user/te_commis')">
				您已获得{{InviteIncome}}元推荐奖励 ，<text>点击提现</text>
			</view>
			<button open-type="share" class="payBtn_cell">
				邀请好友一起助农
			</button>
		</view>
		
		<view class="payBtn_body" v-else>
			<view class="payBtn_tag">
				推荐满3个会员立即返还全部会员费用
			</view>
			<view class="payBtn_cell" @click="payFun">
				￥{{total}}开通会员
			</view>
		</view>
		
		<view class="payMain_body">
			<view class="payMain_top">
				<view class="payMain_titbox">
					<image src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/17428874662333.png" mode="widthFix"></image>
					<view class="payMain_title">
						VIP会员权益
					</view>
				</view>
				<view class="payMain_litbox" @click="nav_to('/pages/user/vipPay/vipDescribe')">
					<view class="payMain_lit">
						会员权益与服务说明
					</view>
					<uni-icons type="right" size="14" color="#fff"></uni-icons>
				</view>
			</view>
			
			<view class="payMain_main" v-if="vipRule && vipRule.Details.length">
				<view class="icons_cell" v-for="(item,index) in vipRule.Details" :key="index">
					<image :src="item.ICON" mode="aspectFill"></image>
					<view class="icons_content">
						<view class="icons_title">
							{{item.Title}}
						</view>
						<view class="icons_lit">
							{{item.Desc}}
						</view>
					</view>
					
				</view>
			</view>
		</view>
		<view style="height: 60rpx;"></view>
		
		<uni-popup ref="payTips">
			<view class="payPopup_body">
				<view class="payPopup_title">
					恭喜您成为VIP会员
				</view>
				<view class="payPopup_main">
					<view class="payPopup_mainCell">
						您已获得
					</view>
					<view class="payPopup_mainCell">
						1、50元现金券
					</view>
					<view class="payPopup_mainCell">
						2、VIP会员权益
					</view>
					<view class="payPopup_mainCell">
						3、推荐会员返佣资格
					</view>
				</view>
				<view class="payPopup_btn" @click="$refs.payTips.close()">
					我知道了
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				banner:[],
				total:365,
				level:0,
				user:null,
				
				vipRule:'',
				InviteIncome:0,
				
				vipPerson:[
					{
						title:'推荐1个',
						count:1,
						money:'立返50',
						subtitle:''
					},
					{
						title:'推荐2个',
						count:2,
						money:'立返50',
						subtitle:''
					},
					{
						title:'推荐3个',
						count:3,
						money:'立返200',
						subtitle:'再送¥100现金券'
					},
					{
						title:'推荐>3个',
						count:4,
						money:'立返10%',
						subtitle:''
					},
				]
			};
		},
		onLoad() {
			this.init()
		},
		onShareAppMessage(res) {
		    //发送给朋友
				let pid = uni.getStorageSync('user').UserID;
		    return {
		        title: `${uni.getStorageSync('user').Name}邀请您一起助农`,
		        path: `/pages/user/vipPay/vipPay`,
						query: `pid=${pid}`,
						imageUrl:'https://giftapp.oss-cn-shenzhen.aliyuncs.com/ads/vip_banner.png'
		    };
		},
		methods:{
			async init(){
				await this.GetVipInfo()
				this.GetVipDetail()
				this.GetBanner()
				this.getUserInfo()
			},
			isVipFun(val){
				if(val.indexOf('VIP')!=-1){
					return true
				}
				return false
			},
			async getUserInfo() {
				let res = await this.$api.post('/User/GetUserInfo', { ID: uni.getStorageSync('user').UserID });
				this.user = res.data;
				// this.user.UserType = 'VIP'
			},
			async GetVipDetail(){
				let res = await this.$api.post('/SaleChannel/Detail')
				if(res.code==0){
					if(res.data){
						this.level = res.data && res.data.ReturnNum ? res.data.ReturnNum : 0
						this.InviteIncome = res.data.InviteIncome || 0
					}
					
				}else{
					this.$u.toast(res.message)
				}
			},
			async GetVipInfo(){
				let res = await this.$api.post('/Member/GetUserType',{
					UserType:'VIP会员'
				})
				if(res.code==0){
					this.vipRule = res.data
					this.total = res.data.Fee || 365
					this.vipPerson = res.data.StepList || []
				}else{
					this.$u.toast(res.message)
				}
			},
			async GetBanner(){
				let res = await this.$api.post('/Banner/GetBanner',{
					PageKey:'vip_top'
				})
				if(res.code==0){
					this.banner = res.data
				}else{
					this.$u.toast(res.message)
				}
			},
			async payFun() {
				let _this = this
				let EventID = uni.getStorageSync('user').UserID
				// 支付订单接口
				let response = await this.$api.post('/Payment/PayV2', {
					EventType: '会员升级',
					EventID,
					body: '开通会员',
					total_fee: this.total,
					SourcePage: 'pages/user/vipPay/vipPay',
					PayChannel: 'weixin',
				});
			
				if (response.code == 0) {
					let payObj = JSON.parse(response.data);
					// console.log(payObj, '==================PayV2----res.data')
			
					uni.requestPayment({
						provider: 'wxpay',
						// #ifdef MP-WEIXIN
						timeStamp: payObj.timeStamp,
						nonceStr: payObj.nonceStr,
						package: payObj.package,
						signType: payObj.signType,
						paySign: payObj.paySign,
						// #endif
						success: async function (res) {
							_this.$pv.msg('支付成功');
							_this.init()
							_this.$refs.payTips.open()
							// uni.$emit('updateVip')
						},
						fail: function (err) {
							_this.$pv.msg('您已取消支付');
						},
					});
				}
			},
		}
	}
</script>

<style lang="scss">

.wrap{
	background-image: linear-gradient(to bottom, #f96a3e 0%, #f6a05e 100%);
	width: 100%;
	height: 100vh;
	overflow-y: scroll;
}
swiper{
	height: 350rpx;
	width: 100%;
	swiper-item{
		width: 100%;
		height: 100%;
		.swiper-item{
			width: 100%;
			height: 100%;
			image{
				width: 100%;
				height: 100%;
			}
		}
		
	}
}
.payBody{
	display: flex;
	align-items: center;
	// justify-content: space-between;
	padding: 24rpx 0rpx;
	.payBody_line{
		// width: calc( (100% - (15%*3)) / 2 );
		width: calc( (100% - (25%*3)) / 2 );
		// height: 200rpx;
		position: relative;
		&::after{
			content: '';
			width: 100%;
			height: 10rpx;
			border-radius: 4rpx;
			background-color: #fff;
			position: absolute;
			top: 50%;
			transform: translate(0,-50%);
		}
	}
	.payBody_Opacity{
		opacity: 0.4;
	}
	.payBody_cell{
		width: 25%;
		// height: 200rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.payBody_tit{
			font-weight: bold;
			font-size: 20rpx;
			color: #fff;
			height: 46rpx;
			display: flex;
			align-items: center;
			text-align: center;
		}
		.payBody_round{
			margin: 4rpx 0;
			border-radius: 50%;
			background-color: #fff;
			width: 50rpx;
			height: 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			image{
				width: 60%;
				height: 60%;
			}
		}
		.payBody_old{
			font-size: 22rpx;
		}
		.payBody_lit{
			font-size: 18rpx;
			height: 18rpx;
		}
	}
}
.payBtn_body{
	.payBtn_cell{
		letter-spacing: 1px;
		margin: 0 24rpx;
		// width: 80%;
		height: 80rpx;
		border-radius: 50rpx;
		background-image: linear-gradient(to right,#fa5320 0%,#f57944 100%);
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: bold;
		font-size: 30rpx;
		color: #fff;
		// position: relative;
		
	}
	.payBtn_tag{
		// position: absolute;
		top: -20rpx;
		left: 0;
		padding: 8rpx 14rpx;
		border-radius: 24rpx;
		color: #fff;
		font-size: 24rpx;
		// font-weight: bold;
		text-align: center;
		margin-bottom: 4rpx;
		text{
			font-size: 24rpx;
			// font-weight: bold;
			color: #5ebddc;
			text-decoration: underline;
		}
	}
}
.payMain_body{
	margin: 24rpx;
	border-radius: 24rpx;
	overflow: hidden;
	.payMain_top{
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fb5d30;
		padding: 24rpx 18rpx;
		.payMain_titbox{
			display: flex;
			align-items: center;
			image{
				width: 36rpx;
				height: 36rpx;
				margin-right: 12rpx;
			}
			.payMain_title{
				font-size: 28rpx;
				font-weight: bold;
				color: #fff;
			}
		}
		.payMain_litbox{
			display: flex;
			align-items: center;
			.payMain_lit{
				font-size: 24rpx;
				color: #eee;
				margin-right: 8rpx;
			}
			image{
				width: 32rpx;
				height: 32rpx;
			}
		}
	}
	.payMain_main{
		background-color: #fff;
		// display: flex;
		// flex-wrap: wrap;
		padding: 12rpx 0;
		.icons_cell{
			// width: 25%;
			display: flex;
			// flex-direction: column;
			align-items: center;
			// justify-content: center;
			// padding: 12rpx;
			padding: 12rpx 24rpx;
			image{
				// width: 60rpx;
				// height: 60rpx;
				
				width: 60rpx;
				height: 60rpx;
			}
			.icons_content{
				margin-left: 24rpx;
				.icons_title{
					// margin-top: 12rpx;
					font-size: 24rpx;
					color: #111;
					// text-align: center;
					
					font-size: 28rpx;
					font-weight: bold;
				}
				.icons_lit{
					font-size: 24rpx;
					color: #999;
				}
			}
			
		}
	}
}

.payPopup_body{
	width: 66vw;
	height: 30vh;
	background-color: #fff;
	border-radius: 24rpx;
	padding: 24rpx;
	.payPopup_title{
		font-size: 28rpx;
		font-weight: bold;
		color: #f57944;
		text-align: center;
		padding-bottom: 12rpx;
	}
	.payPopup_main{
		// height: 83%;
		// overflow-y: scroll;
		.payPopup_mainCell{
			// font-weight: bold;
			font-size: 26rpx;
			color: #111;
			margin-bottom: 8rpx;
		}
	}
	.payPopup_btn{
		width: 60%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		height: 60rpx;
		background: #FF6030;
		border-radius: 50rpx;
		color: #fff;
	}
}
</style>
